package cn.tl.org.controller;

import cn.tl.org.domain.Detail;
import cn.tl.org.domain.Shop;
import cn.tl.org.query.DetailQuery;
import cn.tl.org.query.ShopQuery;
import cn.tl.org.service.IDetailService;
import cn.tl.org.service.IShopService;
import cn.tl.org.utils.AjaxResult;
import cn.tl.org.utils.QueryResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
@Api(tags = "数字字典明细")
//@CrossOrigin
public class DetailController {
    @Autowired
    private IDetailService detailService;
    @PutMapping
    @ApiOperation(value = "新增或修改接口")
    public AjaxResult saveOrUpt(@RequestBody Detail detail){
        try {
            if (detail.getId() == null){
                detailService.save(detail);
            }else {
                detailService.update(detail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            detailService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    @GetMapping("/{id}")
    public Detail findById(@PathVariable("id") Long id){
        return detailService.findById(id);
    }
    @GetMapping
    public List<Detail> findAll(){
        return detailService.findAll();
    }

    @PostMapping
    public QueryResult<Detail> queryPage(@RequestBody DetailQuery query){
        return detailService.queryPage(query);
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids){
        try {
            detailService.patchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }


    }







